import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { CrawlSourceConfigVO, CrawlSourceConfigForm, CrawlSourceConfigQuery } from '@/api/crawl/config/types';

/**
 * 查询爬虫管理列表
 * @param query
 * @returns {*}
 */

export const listCrawlSourceConfig = (query?: CrawlSourceConfigQuery): AxiosPromise<CrawlSourceConfigVO[]> => {
  return request({
    url: '/crawl/config/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询爬虫管理详细
 * @param crawlId
 */
export const getCrawlSourceConfig = (crawlId: string | number): AxiosPromise<CrawlSourceConfigVO> => {
  return request({
    url: '/crawl/config/' + crawlId,
    method: 'get'
  });
};

/**
 * 新增爬虫管理
 * @param data
 */
export const addCrawlSourceConfig = (data: CrawlSourceConfigForm) => {
  return request({
    url: '/crawl/config',
    method: 'post',
    data: data
  });
};

/**
 * 修改爬虫管理
 * @param data
 */
export const updateCrawlSourceConfig = (data: CrawlSourceConfigForm) => {
  return request({
    url: '/crawl/config',
    method: 'put',
    data: data
  });
};
/**
 * 删除爬虫管理
 * @param id
 */
export const delCrawlSourceConfig = (crawlId: string | number | Array<string | number>) => {
  return request({
    url: '/crawl/config/' + crawlId,
    method: 'delete'
  });
};

/**
 * 开启爬虫
 * @param crawlId
 */
export const openCrawl = (crawlId: string | number | Array<string | number>) => {
  return request({
    url: '/crawl/config/open',
    method: 'post',
    data: crawlId
  });
};
/**
 * 关闭爬虫
 * @param crawlId
 */
export const closeCrawl = (crawlId: string | number | Array<string | number>) => {
  return request({
    url: '/crawl/config/close',
    method: 'post',
    data: crawlId
  });
};
